package com.stable.model;

import com.stable.spider.ths.XLSData;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Font;

import java.util.Arrays;
import java.util.List;

public class FCFF {

    public static void FCFFwriteXls(String code, HSSFWorkbook workbook, List<XLSData> benefitList, List<XLSData> cashList, List<XLSData> debtList) {
        HSSFSheet sheet = workbook.createSheet("计算FCFF");// 创建工作表(Sheet)
        List nullList = Arrays.asList();

        HSSFUtil.row(workbook, sheet, 0, code + ":报告参数", "科目\\时间", benefitList);
        HSSFUtil.row(workbook, sheet, 1, "汇总计算（单位：万）", "", nullList);
        HSSFUtil.rowFormula(workbook, sheet, 2, "EBIT*(1-税率)", "CS17/10000", benefitList, "");
        HSSFUtil.rowFormula(workbook, sheet, 3, "加：折旧", "CS20/10000", benefitList, "");
        HSSFUtil.rowFormula(workbook, sheet, 4, "减：资本支出", "CS28/10000", benefitList, "");
        HSSFUtil.rowFormula(workbook, sheet, 5, "减：非现金性流动资本的增加(减少)", "CS39/10000", benefitList, "");
        HSSFUtil.rowFormula(workbook, sheet, 6, "FCFF 单位:万", "CS3+CS4-CS5-CS6", benefitList, "");

        HSSFRow row7 = sheet.createRow(7);
        HSSFUtil.rowColumn(workbook, row7, 0, "注意财务资产负债表变化：货币资金=货币资金+拆出资金，导致FCFF有影响", Font.COLOR_RED);

        HSSFUtil.row(workbook, sheet, 8, "净利润", "净利润(元)", cashList);
        HSSFUtil.rowFormula(workbook, sheet, 9, "FCFF/净利润", "CS7/CS9*10000", benefitList, "0.00%");

        HSSFUtil.row(workbook, sheet, 11, "第1步，通过利润表计算EBIT-所得税)", "", nullList);
        HSSFUtil.row(workbook, sheet, 12, "利润表(原始货币, 元)", "", nullList);
        HSSFUtil.row(workbook, sheet, 13, "财务费用(元)", "财务费用(元)", benefitList);
        HSSFUtil.row(workbook, sheet, 14, "营业利润(元)", "三、营业利润(元)", benefitList);
        HSSFUtil.row(workbook, sheet, 15, "减：所得税费用(元)", "减：所得税费用(元)", benefitList);
        HSSFUtil.rowFormula(workbook, sheet, 16, "EBIT-所得税（=营业利润+财务费用-所得税）", "CS14+CS15-CS16", benefitList, "");


        HSSFUtil.row(workbook, sheet, 17, "", "", nullList);
        HSSFUtil.row(workbook, sheet, 18, "第2步，从现金流表的补充资料中找折旧", "", nullList);
        HSSFUtil.row(workbook, sheet, 19, "折旧", "固定资产折旧、油气资产折耗、生产性生物资产折旧(元)", cashList);


        HSSFUtil.row(workbook, sheet, 20, "", "", nullList);
        HSSFUtil.row(workbook, sheet, 21, "第3步，通过资产负债表计算资本支出", "", nullList);
        HSSFUtil.row(workbook, sheet, 22, "长期股权投资(元)", "长期股权投资(元)", debtList);
        HSSFUtil.row(workbook, sheet, 23, "固定资产合计(元)", "固定资产合计(元)", debtList);
        HSSFUtil.row(workbook, sheet, 24, "无形资产(元)", "无形资产(元)", debtList);
        HSSFUtil.row(workbook, sheet, 25, "长期待摊费用(元)", "长期待摊费用(元)", debtList);
        HSSFUtil.row(workbook, sheet, 26, "递延所得税资产(元)", "递延所得税资产(元)", debtList);
        HSSFUtil.rowFormula(workbook, sheet, 27, "资本支出", "SUM(CS23:CS27)-SUM(CT23:CT27)", benefitList, "");

        HSSFUtil.row(workbook, sheet, 28, "", "", nullList);
        HSSFUtil.row(workbook, sheet, 29, "第4步，通过资产负债表计算非现金性流动资本的增加(减少)", "", nullList);
        HSSFUtil.row(workbook, sheet, 30, "流动资产合计(元)", "流动资产合计(元)", debtList);
        //货币资金+拆出资金
        HSSFUtil.row(workbook, sheet, 31, "货币资金(元)", "货币资金(元)", debtList);
        HSSFUtil.row(workbook, sheet, 32, "拆出资金", "", nullList);
        HSSFUtil.rowFormula(workbook, sheet, 33, "资本支出", "CS31-CS32-C33", benefitList, "");


        HSSFUtil.row(workbook, sheet, 34, "流动负债合计(元)", "流动负债合计(元)", debtList);
        HSSFUtil.row(workbook, sheet, 35, "一年内到期的非流动负债(元)", "一年内到期的非流动负债(元)", debtList);
        HSSFUtil.rowFormula(workbook, sheet, 36, "流动负债", "CS35-CS36", benefitList, "");
        HSSFUtil.rowFormula(workbook, sheet, 37, "流动资本", "CS34-CS37", benefitList, "");
        HSSFUtil.rowFormula(workbook, sheet, 38, "非现金性流动资本的增加(减少)", "CS38-CT38", benefitList, "");

//        HSSFRow row3 = sheet.createRow(3);
//        HSSFCell row3cell0 = row3.createCell(0);
//        row3cell0.setCellValue("        财务费用2");
//        HSSFCell row3cell1 = row3.createCell(1);
//        row3cell1.setCellValue("1");
//        HSSFCell row3cell2 = row3.createCell(2);
//        row3cell2.setCellValue("2");
//        row3cell2.setCellStyle(RedColor(workbook));
//        HSSFCell row3cell3 = row3.createCell(3);
//        row3cell3.setCellValue("3");
//        row3cell3.setCellStyle(GreenColor(workbook));

//        HSSFRow row4 = sheet.createRow(4);
//        HSSFCell row4cell0 = row4.createCell(0);
//        row4cell0.setCellValue("");
//        HSSFCell row4cell1 = row4.createCell(1);
//        row4cell1.setCellFormula("B3+B4");
    }
}
